<?php session_start(); ?>
<?php mb_internal_encoding("UTF-8"); ?>
<?php include('db.inc'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="cs" xml:lang="cs">                   
  <head>	                                   
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Language" content="cs" />                                   
    <meta name="author" content="Pavel Kohout, Petr Koula, Alexandr Krátký, Tomáš Rejdal, Martina Zemaníková" />	                                   
    <meta name="keywords" content="regionální, potravina, středočeský, kraj, regionální potravina, středočeský kraj, potravina středočeský" />	                                   
    <meta name="Description" content="Semestrální práce na téma Regionální potraviny Středočeského kraje z předmětu IT CS" />	                                   
    <meta name="robots" content="all" />	                                   
    <title>Regionální potraviny                                   
    </title>	                                   
    <link rel="StyleSheet" href="css/screen.css" type="text/css" media="screen" />	                                   
    <link rel="stylesheet" href="css/tisk.css" type="text/css" media="print" />	                                   
    <base target="text" />  
	
	
	
	 <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>


 

	
	
	                  
  </head>          
  <?php  
    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");  
    mysql_select_db($db) or die ("Unable to select database!");
    mysql_query("SET NAMES 'utf8'");
    mysql_query("SET CHARACTER SET 'utf8'");
    $query = "select f.id, f.name, f.img_file, f.desc, c.name, p.name, p.add_street, p.add_city, p.add_zipcode, p.email, p.homepage, p.desc, p.latitude, p.longtitude
    from food f inner join category c on f.category_id = c.id
    inner join producer p on f.producer_id = p.id
    where f.id = ".$_GET['id'];
    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
    $row = mysql_fetch_row($result);
  ?>          
  <body >    
     <script type="text/javascript">

      function initialize() {
        var mapDiv = document.getElementById('map-canvas');
        var map = new google.maps.Map(mapDiv, {
          center: new google.maps.LatLng(<?php echo $row[12]; ?>, <?php echo $row[13]; ?>),
          zoom: 14,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        });
      
        var infoWindow = new google.maps.InfoWindow({
          position: map.getCenter(),
          content: '<?php echo $row[5]; ?><br /><?php echo $row[6]; ?>'
        });
        infoWindow.open(map);
      }
      

      google.maps.event.addDomListener(window, 'load', initialize);
    </script>

  
                                
    <table class="tabulka2">                                                   
      <tr class="ost">                                                                     
        <td colspan="3"><h1><?php echo $row[1]; ?></h1></td>                                                   
      </tr>                                                   
      <tr class="ost">                                                                 
        <td colspan="3" class="osta"> 
            <table>
			<tr>
			<td colspan="3"><br /></td>
			</tr>
              <tr>
                 <td>
                     <img alt="Regionální potravina obrázek" src="images/<?php echo $row[2]; ?>"/>           </td>
                 <td class="nopadd58" colspan="2"><span class="normal">
                     Kategorie: <?php echo $row[4]; ?><br /></span>
               
                     
                          <?php echo $row[3]; ?>                </td>
              </tr>
			  </table>
			  <table>
              <tr>
                  <td colspan="1">
                    <span class="normal"><br />
                      Výrobce: <?php echo $row[5]; ?></span><br />
                      <?php echo $row[11]; ?><br /><br />
                    
                    <span class="normal">
                       <?php echo $row[6]; ?><br />
                       <?php echo $row[7]; ?><br />
                       <?php echo $row[8]; ?><br />
                       <a href="mailto:<?php echo $row[9]; ?>"><?php echo $row[9]; ?></a><br />
                       <a href="http://<?php echo $row[10]; ?>" target="_blank"><?php echo $row[10]; ?></a><br />
                   </span>                  </td>
				  <td rowspan="2"><div id="map-canvas" style="width: 500px; height: 400px;"></div></td>
              </tr>
              <tr>
                  <td>
                    <span class="normal">
                      <br />
			Produkt prodává:<br />
                    </span>
                    
                       <?php 
                        $query = "select s.name from seller s inner join food_has_seller fhs on s.id = fhs.seller_id
                                  inner join food f on fhs.food_id = f.id
                                  where f.id = ".$_GET['id'];
                        $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
                        while($row = mysql_fetch_row($result)) {
                          echo "<span>".$row[0]."</span><br />";
                        }
                       ?>
                       <a href="http://<?php echo $row[10]; ?>"><?php echo $row[10]; ?></a><br />                  </td>
			  </tr>
          </table>                                                                            
        </td>                                                
      </tr>                                                   
      <tr>                                                                 
        <td height="1" colspan="3" class="nopadd55"></td>                                                
      </tr>    
      
      <tr>
          <td colspan="3">
              <?php 
                if (!isset($_GET['error']) && isset($_SESSION)) {
                   unset($_SESSION['name']);
                   unset($_SESSION['email']);
                   unset($_SESSION['comment']);
                }
                if (isset($_GET['error']) && $_GET['error'] == "validation") {
                   ?>
                       <span class="normalred">Všechny položky jsou povinné</span>
                   <?php
                }
                if (isset($_GET['error']) && $_GET['error'] == "captcha") {
                   ?>
                       <span class="normalred">Nesprávný ověřovací kód</span>
                   <?php
                }
		if (isset($_GET['error']) && $_GET['error'] == "validation_email") {
                   ?>
                       <span class="normalred">Neplatný email</span>
                   <?php
                }
              ?>
              <form action="saveComment.php" method="POST">
                <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
                <table align="left">
                  <tr>
                    <td colspan="2" class="osta"><span class="normal"> Vaše zkušenosti s tímto výrobkem:</span></td>
                  </tr>
                  <tr class="ost">
                     <td align="right" class="ostar">Jméno:</td>
                     <td align="left"><input type="text" name="name" size="25" maxlength="45" value="<?php if (isset($_SESSION['name'])) {echo $_SESSION['name'];} ?>" /></td>
                  </tr>
                  <tr class="ost">
                     <td align="right" height="37">E-mail:<br /> 
                       <span class="normal_maly">(nebude zveřejněn)</span> </td>
                     <td align="left"><input type="text" name="email" size="25" maxlength="100" value="<?php if (isset($_SESSION['email'])) {echo $_SESSION['email'];} ?>" /></td>
                  </tr>
                  <tr class="ost">
                     <td align="right">Komentář:</td>
                     <td align="left"><textarea name="comment" cols="40" rows="3" wrap="soft"><?php if (isset($_SESSION['comment'])) {echo $_SESSION['comment'];} ?></textarea></td>
                  </tr>
                  <tr class="ost">
                     <td align="right"><img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br />
		                    <label for="security_code">Ověřovací kód: </label></td>
                     <td align="left"><input id="security_code" name="security_code" type="text" /></td>
                  </tr>
                  <tr>
                     <td></td>
                     <td align="left"><input type="submit" value="Vložit"/></td>
                  </tr>
				                                             <tr>
				                                               <td height="6"></td>
                  </tr>
				                                             <tr>
                                             <td class="osta"><span class="normal">Poslední reakce:</span></td>
											              </tr>
                </table>
              </form>
          </td>
      </tr>
      
                <?php 
                        $query = "select name, cd, body from comments where food_id = ".$_GET['id']." order by cd desc";
                        $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
                        while($row = mysql_fetch_row($result)) {
                          ?>
                               <tr>
                                   <td colspan="3">
                                       <table class="tabulka5" align="left">

                                           <tr>
                                               <td align="left" class="osta44">
                                                   <span class="normal"><?php echo $row[0]; ?></span> | <span class="normal_maly"><?php echo date('d. m. Y  H:i', strtotime($row[1])); ?></span>                                               </td>
                                           </tr>
                                           <tr>
                                               <td align="left">
                                                  <?php echo nl2br($row[2]); ?>                                               </td>
                                           </tr>
                                       </table>
                                   </td>
                               </tr>
                          
                          <?php
                        }
                        mysql_close($connection);  
                ?>
          
		      <tr>  
			        <tr>                                                                 
        <td height="8" colspan="3" align="left" class="osta"></td>                                                   
      </tr>                                                               
        <td height="2" colspan="3" class="nopadd55"></td>                                                
      </tr>                                        
      <tr>                                                                 
        <td height="8" colspan="3" align="left" class="osta"></td>                                                   
      </tr>                                                
      <tr>                                                                 
        <td align="left" height="15" colspan="2">                                                                              
          <div class="bez">                                                                                               
            <a href="http://validator.w3.org/check?uri=referer" target="_blank">                                                                                                        
              <img         src="images/valid-xhtml10.png"         alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a>		&nbsp; 		                                                                                           
            <a href="http://jigsaw.w3.org/css-validator/check/referer" target="_blank">                                                                                                                 
              <img src="images/vcss.gif"             alt="Ověřit CSS!" />    </a>		                                                                             
          </div>	</td>	                                                               
        <td width="60%" colspan="1" class="ostat">                                                                            
          <a href="javascript:window.print()" class="odkaz2">Vytisknout</a>                                                                            
          <span class="normal_maly"> |                                                                              
          </span>                                                                            
          <a href="prohlaseni.php" target="_self" class="odkaz2">Prohlášení o přístupnosti</a>  </td>                                                
      </tr>                                  
    </table>                    
  </body>
</html>